package com.sale.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import com.sale.system.domain.PrintDictionary;
import com.sale.system.domain.SysPrintTemplate;
import com.sale.system.domain.dto.ConfigContentDto;
import com.sale.system.domain.dto.SysPrintTemplateDto;
import com.sale.system.domain.dto.SysTagSummaryDto;
import com.sale.system.domain.vo.ConfigContentVo;
import com.sale.system.domain.vo.DefaultValueVo;
import com.sale.system.domain.vo.SysPrintTemplateVo;
import com.sale.system.service.ISysPrintTemplateService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @Description 打印模板控制层
 * @Date 23-03-15
 * @Author hl
 **/
@RequiredArgsConstructor
@RestController
@RequestMapping("/printConfig")
public class SysPrintTemplateController extends BaseController {

    private final ISysPrintTemplateService sysPrintTemplateService;


    /**
     * 获取打印模板页面
     */
    //@SaCheckPermission("toolConfig:print:list")
    @GetMapping("/list")
    public TableDataInfo<SysPrintTemplateDto> list(SysPrintTemplateVo sysPrintTemplateVo, PageQuery pageQuery) {
        return sysPrintTemplateService.selectPrintTemplateList(sysPrintTemplateVo, pageQuery);
    }

    /**
     * 获取打印模板页面
     */
    @GetMapping("/listNotPage")
    public R<?> listNotPage(SysPrintTemplateVo sysPrintTemplateVo) {
        return R.ok(sysPrintTemplateService.listNotPage(sysPrintTemplateVo));
    }

    /**
     * 新增打印模板
     */
    //@SaCheckPermission("system:printConfig:add")
    @Log(title = "打印模板", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R<Void> add(@Validated @RequestBody SysPrintTemplate sysPrintTemplate) {
        return toAjax(sysPrintTemplateService.insertPrintTemplate(sysPrintTemplate));
    }

    /**
     * 配置内容
     */
    //@SaCheckPermission("system:printConfig:config")
    @PostMapping("/configContent")
    public R<Void> configContent(@RequestBody ConfigContentVo configContentVo) {
        return toAjax(sysPrintTemplateService.configContent(configContentVo));
    }

    /**
     * 配置内容查看
     */
    //@SaCheckPermission("system:printConfig:view")
    @GetMapping("/getView/{id}")
    public R<ConfigContentDto> getView(@PathVariable("id") Long id) {
        return R.ok(sysPrintTemplateService.getView(id));
    }

    /**
     * 修改默认状态
     */
    @PutMapping("/updateDefaultValue")
    public R<Void> updateDefaultValue(@RequestBody DefaultValueVo defaultValueVo) {
        return toAjax(sysPrintTemplateService.updateDefaultValue(defaultValueVo));
    }

    /**
     * 根据编号获取详细信息
     */
    //@SaCheckPermission("system:printConfig:query")
    @GetMapping(value = "/{printId}")
    public R<SysPrintTemplateDto> getPrintTemplateInfo(@PathVariable long printId) {
        return R.ok(sysPrintTemplateService.selectPrintTemplateById(printId));
    }

    /**
     * 点击配置获取JSON数据
     */
    //@SaCheckPermission("system:printConfig:config")
    @GetMapping(value = "/config/{printId}")
    public R<String> getPrintTemplateConfig(@PathVariable long printId) {
        return R.ok(sysPrintTemplateService.getPrintTemplateConfig(printId));
    }

    /**
     * 删除打印模板
     */
    //@SaCheckPermission("system:printConfig:remove")
    @Log(title = "打印模板", businessType = BusinessType.DELETE)
    @DeleteMapping("/{printId}")
    public R<Void> remove(@PathVariable("printId") String printId) {
        return toAjax(sysPrintTemplateService.deletePrintTemplate(printId));
    }

    /**
     * 修改打印模板
     */
    //@SaCheckPermission("system:printConfig:edit")
    @Log(title = "打印模板", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public R<Void> edit(@RequestBody SysPrintTemplate sysPrintTemplate) {
        return toAjax(sysPrintTemplateService.updatePrintTemplateEdit(sysPrintTemplate));
    }

    /**
     * 获取模板字段
     */
    @GetMapping(value = "/details/{printCorrelation}")
    public R<List<SysTagSummaryDto>> getPrintTemplateDetails(@PathVariable long printCorrelation) {
        return R.ok(sysPrintTemplateService.getPrintTemplateDetails(printCorrelation));
    }

    /**
     * 通过模板类型查对应的模板列表
     */

    @GetMapping("/typeList")
    public R<List<SysPrintTemplateDto>> typeList(int type) {
        List<SysPrintTemplateDto> list = sysPrintTemplateService.selectList(type);
        return R.ok(list);
    }

    /**
     * 通过模板id新增字段
     */
    @PostMapping("/dictionary")
    public R<Void> dictionary(@RequestBody List<PrintDictionary> list) {
        return toAjax(sysPrintTemplateService.insertPrintDictionary(list));
    }


}
